//
//  DDContactCell.m
//  PrivateCloud
//
//  Created by mars on 13-10-28.
//  Copyright (c) 2013年 sarah doo. All rights reserved.
//

#import "DDContactCell.h"
#import "DDContactInfo.h"

@implementation DDContactCell
@synthesize model,button,contactModel;
- (void)dealloc
{
    [_personNameLabel release];
    [_personPhoneHomeLabel release];
    [_personPhoneMoveLabel release];
    [super dealloc];
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        
        _personNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 40, 300, 20)];
        _personNameLabel.backgroundColor = [UIColor clearColor];
        _personNameLabel.textColor  = [UIColor greenColor];
        _personNameLabel.font = [UIFont systemFontOfSize:10];
        [self.contentView addSubview:_personNameLabel];
        
        
        _personEmailLabel = [[UILabel alloc] initWithFrame:CGRectMake(80, 10, 300, 20)];
        _personEmailLabel.backgroundColor = [UIColor clearColor];
        _personEmailLabel.textColor  = [UIColor orangeColor];
        _personEmailLabel.font = [UIFont systemFontOfSize:10];
        [self.contentView addSubview:_personEmailLabel];
        
        _personPhoneMoveLabel = [[UILabel alloc] initWithFrame:CGRectMake(80, 30, 300, 20)];
        _personPhoneMoveLabel.backgroundColor = [UIColor clearColor];
        _personPhoneMoveLabel.textColor  = [UIColor blackColor];
        _personPhoneMoveLabel.font = [UIFont systemFontOfSize:10];
        [self.contentView addSubview:_personPhoneMoveLabel];
        
        _personPhoneHomeLabel = [[UILabel alloc] initWithFrame:CGRectMake(80, 50, 300, 20)];
        _personPhoneHomeLabel.backgroundColor = [UIColor clearColor];
        _personPhoneHomeLabel.textColor  = [UIColor blackColor];
        _personPhoneHomeLabel.font = [UIFont systemFontOfSize:10];
        [self.contentView addSubview:_personPhoneHomeLabel];
        
        _personPhoneWorkLabel = [[UILabel alloc] initWithFrame:CGRectMake(80, 70, 300, 20)];
        _personPhoneWorkLabel.backgroundColor = [UIColor clearColor];
        _personPhoneWorkLabel.textColor  = [UIColor blackColor];
        _personPhoneWorkLabel.font = [UIFont systemFontOfSize:10];
        [self.contentView addSubview:_personPhoneWorkLabel];
        
        _personPhoneiPhoneLabel = [[UILabel alloc]initWithFrame:CGRectMake(80, 100, 300, 20)];
        _personPhoneiPhoneLabel.backgroundColor = [UIColor clearColor];
        _personPhoneiPhoneLabel.textColor = [UIColor blackColor];
        _personPhoneiPhoneLabel.font = [UIFont systemFontOfSize:10];
        [self.contentView addSubview:_personPhoneiPhoneLabel];
        
        button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.userInteractionEnabled = NO;
        button.frame = CGRectMake(270, 40, 30, 30);
        [button setImage:[UIImage imageNamed:@"check_false.png"] forState:UIControlStateNormal];
        [self.contentView addSubview:button];
        
        
    }
    return self;
}

-(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event{
    NSLog(@"contacts-----------------");
    return true;
}

- (void)setModel:(DDContactModel*)_contactModel{
    if (contactModel != _contactModel) {
        [contactModel release];
        contactModel = [_contactModel retain];
    }
    
    if ([[contactModel name]length] > 10) {
        NSRange range;
        range.location = 0;
        range.length = 8;
        NSString* subName = [[contactModel name]substringWithRange:range];
        subName = [NSString stringWithFormat:@"%@%@",subName,@"..."];
        _personNameLabel.text = subName;
    }
    else{
            _personNameLabel.text = [contactModel name];
    }
    
    if ([contactModel email]!=nil) {
        _personEmailLabel.text = [NSString stringWithFormat:@"电子邮件: %@",[contactModel email]];
    }
    else{
        _personEmailLabel.text = [NSString stringWithFormat:@"电子邮件: %@",@""];
    }
    
    
    _personPhoneMoveLabel.text = [NSString stringWithFormat:@"移动电话: %@",[contactModel mobileNo]];
    _personPhoneHomeLabel.text = [NSString stringWithFormat:@"家庭电话: %@",[contactModel homeNo]];
    _personPhoneWorkLabel.text = [NSString stringWithFormat:@"工作电话: %@",[contactModel workNo]];
    _personPhoneiPhoneLabel.text = [NSString stringWithFormat:@"iPhone: %@",[contactModel iphoneNo]];
    
    if ([contactModel isSelected]) {
        [button setImage:[UIImage imageNamed:@"check_true.png"] forState:UIControlStateNormal];
    }
    else{
        [button setImage:[UIImage imageNamed:@"check_false.png"] forState:UIControlStateNormal];
    }
    
}
@end
